using System.Collections;
using UnityEngine;

public class PlayerCharacter : Character
{
	private float survivalTime;

	private float startTime;

	private bool boostOnWebGL;

	private readonly Vector2 v2_zero = Vector2.zero;

	public float SurvivalTime
	{
		get
		{
			return survivalTime;
		}
	}

	public override int Rank
	{
		get
		{
			return rank;
		}
		set
		{
			rank = value;
			ScoreManager.LastRank = rank;
		}
	}

	public override int KillCount
	{
		get
		{
			return killCount;
		}
		set
		{
			killCount = value;
			ScoreManager.LastKill = killCount;
		}
	}

	protected override void SetMass(int value)
	{
		base.SetMass(value);
		if (ScoreManager.LastMass < value)
		{
			ScoreManager.LastMass = value;
		}
	}

	private void OnEnable()
	{
		AnalogController.OnAnalogstickValueChange += AnalogController_OnAnalogstickValueChange;
		base.name = Values.Instance.PlayerName;
		nameText.text = Values.Instance.PlayerName;
		FollowingCamera.instance.SetTargetCameraSize(Values.Instance.InitialCameraSize);
		survivalTime = 0f;
		startTime = Time.time;
	}

	private void OnDisable()
	{
		AnalogController.OnAnalogstickValueChange -= AnalogController_OnAnalogstickValueChange;
	}

	private void AnalogController_OnAnalogstickValueChange(AnalogType type, AnalogData data)
	{
		if (data.isActive && type == AnalogType.Left && data.axes != v2_zero && !base.IsHitted)
		{
			moveDirection = data.axes.normalized;
		}
	}

	public override void Initialize(int index, Vector3 position, int mass)
	{
		ScoreManager.LastMass = 0;
		base.Initialize(index, position, mass);
		type = GameManager.Instance.SelectedSkinIndex;
		base.Mass = mass;
		survivalTime = Time.time;
	}

	protected override void FixedUpdate()
	{
		if (base.IsAlive)
		{
			survivalTime = Time.time - startTime;
			if ((float)base.Mass > 13f && (GameManager.Instance.boostButton.IsTouching || boostOnWebGL))
			{
				base.BoostEnabled = true;
			}
			else
			{
				base.BoostEnabled = false;
			}
		}
		base.FixedUpdate();
	}

	protected override IEnumerator KillRoutine()
	{
		FollowingCamera.instance.SetTargetCameraSize(Values.Instance.MaxCameraSize);
		DisablePhysics();
		anim.Play("DieAnim");
		yield return new WaitForSeconds(Values.Instance.DieAnimDuration);
		GameManager.Instance.EndGame();
		base.transform.parent.gameObject.SetActive(false);
	}
	 protected override bool IsPlayerCharacter()
    {
        return true; // 表示这是玩家角色
    }
}
